package com.service.user.constructor;

import com.controller.user.request.UserRequest;
import com.model.User;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.stereotype.Component;


@Component
public class UserConstructor {
    public User constructUser(UserRequest request) {
        String name = request.getName();
        String password = request.getPassword();
        int departmentId = request.getDepartmentId();
        User user = new User();
        user.setName(name);
        user.setPassword(md5encrypt(name, password));
        user.setDepartmentId(departmentId);
        return user;
    }

    public String md5encrypt(String name, String password) {
        String keyStr = String.format("%s%s", name, password);
        return DigestUtils.md5Hex(keyStr);
    }
}